package com.example.coco.Controller;


import com.example.coco.model.Admin;
import com.example.coco.model.Cusumer;
import com.example.coco.res.AdminMapper;
import com.example.coco.res.CusumerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@RestController
public class Addadmin {
    @Autowired
    AdminMapper adminMapper;
    @RequestMapping("/addAdmin")
    @ResponseBody
    public Object addAdminuser(@RequestParam Map<String, Object> params)
    {
        String userid = (String) params.get("userid");
        String userpassword = (String) params.get("userpassword");


//        cusumer.setUserid(userid);
//        cusumer.setUserpassword(userpassword);
//        cusumerMapper.insertCusumer(cusumer);

        String a = adminMapper.adminlog(userid);
        if (a != null && !a.equals("")){
            return new ModelAndView("regError");
        }else{

            Admin admin = new Admin();
            admin.setUserid(userid);
            admin.setUserpassword(userpassword);
            adminMapper.insertAdminuser(admin);
            return new ModelAndView("Adminindex");
        }
//        return new ModelAndView("login");

    }
}
